import json
from urllib3 import *
from base64 import b64encode
import re


def get_ip_route(ip,username,password):
    disable_warnings()
    http = PoolManager()

    headers = {}

    headers['Accept'] = 'application/yang-data+json'
    headers['Content-Type'] = 'application/yang-data+json'

    user_pass_str = username + ':' + password
    user_pass_str_encode = user_pass_str.encode()
    userAndPass = b64encode(user_pass_str_encode).decode("ascii")

    headers["Authorization"] = 'Basic %s' % userAndPass

    url = "https://" + ip + "/restconf/data/ietf-routing:routing/routing-instance"

    r = http.request('GET', url, headers=headers)

    return json.loads(r.data.decode())['ietf-routing:routing-instance'][0]['routing-protocols']['routing-protocol'][0]['static-routes']['ietf-ipv4-unicast-routing:ipv4']['route']

if __name__ == "__main__":
    username = "admin"
    password = "Cisc0123"
    ip = "10.1.1.253"
    for x in get_ip_route(ip, username, password):
        print(x["destination-prefix"],'via',x['next-hop']['next-hop-address'])